const express = require("express");
const exApp = require("../index");
const router = express.Router();
const mysql = require("../connect/pomsql");
const { SuccessModule, ErrorModule } = require("../model/resModel");
const { resHandler } = require("../model/resHandler.js");
const path = require("path");
const multer = require("multer");







// 添加图片

const MAO = require("multer-aliyun-oss");
const { type } = require("os");
const { title } = require("process");
//dest：图片要保存的路径
let files = [];
const storage = multer.diskStorage({
  //存储的位置
  destination(req, file, cb) {
    cb(null, "./uploads/");
  },
  filename(req, file, cb) {
    cb(null, file.originalname);
  },
});

const upload = multer({
  storage,
});
exApp.post("/addimg", upload.single("file"), (req, res) => {
  // console.log(req);
  //给客户端返回图片的访问地址 域名 + 文件名字
  //因为在 app.js文件里面我们已经向外暴漏了存储图片的文件夹 uploa
  const url = "http://localhost:8888/uploads/" + req.file.filename;
  //      res.json({url})
  // console.log(url);
	console.log(res)
	res.status(200).send("User Page"); 
  
});
// 小程序
exApp.post('/addfabuall', async function (req, res) {
  const {  img,txt,type,userid,label} = req.body
	let create_up = new Date().toLocaleString()
	// , txt, type,userid, '${txt}', '${type}',  '${userid}'
  let sql = `INSERT INTO lxfxcx(img,txt,type,userid,label,create_up) VALUES ('${img}','${txt}', '${type}',  '${userid}','${label}','${create_up}' )`;
  let data = await mysql(sql)
  res.json({
    code: 200,
    data
  })
})





// 开放静态图片端口
exApp.use(express.static(path.resolve("./public")));